# -*- coding: utf-8 -*-
from sqlalchemy import Column, String, Integer, Text, Binary, Boolean, DateTime, Enum, Float, BigInteger
from adminApp.extensions import db
from .base import BaseModel


class WarnLogs(BaseModel, db.Model):
    '''警报记录'''
    title = Column(String(128))     # 标题
    warn_type = Column(String(128)) # 警报类型 offline ReadWriteError hd_temperature_warn
    warn_txt = Column(Text)         # 警报内容
    warn_txt_md5 = Column(Text)
    status = Column(String(32))     # 处理状态  wait work over
    solver = Column(String(32))     # 警报处理人
    send_warns = Column(Integer, default=0) # 发送警报到处理人设备 次数
    last_send_warn = Column(DateTime, default=db.func.now())   # 上次发送警报到处理人设备 日期
    # 备注
    remark = Column(Text)

    machine_id = db.Column(db.Integer, db.ForeignKey('machine.id', ondelete='CASCADE'), nullable=False, index=True)
    machine = db.relationship('Machine', back_populates='warn_logs')